﻿using JESAI.Application.Abstractions.Admin;
using JESAI.Application.Abstractions.Admin.Dtos.Logging;
using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.Sys;
using JESAI.AutoMapper.ObjectMapping;
using JESAI.Core.Attributes;
using JESAI.Core.Extensions;
using JESAI.Platform.Domain.Admin.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JESAI.Application.Service.Admin
{
    [AppService]
    public class LoggingService : ILoggingService
    {
        private readonly ILoggingRepository _loggingRepository;

        public LoggingService(ILoggingRepository loggingRepository)
        {
            _loggingRepository = loggingRepository;
        }
        public BasePageOutput<List<LoggingDto>> QueryLogList(QueryLogListInput input)
        {
            var totalNumber = 0;
            var modelList=_loggingRepository._DbQueryable
                                .WhereIF(!input.ServiceName.IsEmpty(), it => it.ProjectName == input.ServiceName)
                                 .WhereIF(!input.Level.IsEmpty(), it => it.LogType == input.Level)
                                 .ToPageList(input.PageIndex, input.PageSize, ref totalNumber);
            return new BasePageOutput<List<LoggingDto>> { Data = modelList.MapTo<List<LoggingDto>>(), CurrentPage = input.PageIndex, Total = totalNumber };
        }
    }
}
